class Solution {
public:
    int findNumberOfLIS(vector<int>& a) {
        int n = a.size();
        vector<int>f(n, 1), cnt(n, 1);
        int len = 1, ans_cnt = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (a[j] < a[i]) {
                    if (f[i] == f[j] + 1)cnt[i] += cnt[j];
                    else if (f[i] < f[j] + 1) {
                        f[i] = f[j] + 1;
                        cnt[i] = cnt[j];
                    }
                }
            }
            if (f[i] == len) ans_cnt += cnt[i];
            else if (f[i] > len) {
                len = f[i];
                ans_cnt = cnt[i];
            }
        }
        return ans_cnt;
    }
};